package com.SmartCampus.system.service.impl;

import com.SmartCampus.system.common.ErrorCode;
import com.SmartCampus.system.exception.BusinessException;
import com.SmartCampus.system.mapper.CourseMapper;
import com.SmartCampus.system.model.dto.course.CourseQueryRequest;
import com.SmartCampus.system.model.entity.Course;
import com.SmartCampus.system.model.vo.CourseVO;
import com.SmartCampus.system.service.CourseService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author wangliang
* @description 针对表【course(课程表)】的数据库操作Service实现
* @createDate 2024-12-26 18:54:38
*/
@Service
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course>
    implements CourseService {

    @Resource
    private CourseMapper courseMapper;

    @Override
    public Page<CourseVO> getAll(Page<CourseVO> page, CourseQueryRequest courseQueryRequest) {

        // 自定义分页查询
        List<CourseVO> courseVOS = courseMapper.getAll(page, courseQueryRequest);
        if (courseVOS == null) {
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, "查询失败");
        }
        // 设置分页结果
        page.setRecords(courseVOS);
        return page;
    }

    @Override
    public Page<CourseVO> getStudent(Page<CourseVO> page, CourseQueryRequest courseQueryRequest, String clazzName) {
        List<CourseVO> courseVOS = courseMapper.getStudent(page, courseQueryRequest, clazzName);
        if (courseVOS == null) {
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, "查询失败");
        }
        page.setRecords(courseVOS);
        return page;
    }

    @Override
    public Page<CourseVO> getTeacher(Page<CourseVO> page, CourseQueryRequest courseQueryRequest, Long teacherId) {
        List<CourseVO> courseVOS = courseMapper.getTeacher(page, courseQueryRequest, teacherId);
        if (courseVOS == null) {
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, "查询失败");
        }
        page.setRecords(courseVOS);
        return page;
    }
}




